var ajaxCart    = new ajaxLoader();
var ajaxPage    = new ajaxLoader();
function getId(id)
{
	try{
		return document.getElementById(id);
	}catch(e){}
	return false;
}
function isEmail(s)
{
    var regm=/([a-zA-Z0-9|-|_]+)(@)([a-zA-Z0-9|-|_]+)(.)([a-zA-Z]+)/gi;
    var r=s.match(regm);
    if(r==null)return false;
    return true;
}
function addcart(id,ta)
{
    ajaxCart.init({url: url_root+'as/addcart',func:addcartsuccess});
    ajaxCart.ta=ta;
    ajaxCart.send('id='+id);
}
function addcartsuccess(obj)
{
    if(obj.status=='ok')
    {
        getId('listcartright').innerHTML=obj.cart;
        ajaxCart.ta.innerHTML='<img src="'+url_root+'images/added.jpg" height=10> Added';
        if(obj.count>0)
        {
           getId('bookcart').style.display='';
        }else
        {
            getId('bookcart').style.display='none';
        }
    }
}
function openpopup(url,w,h)
{
    opener = window.open(url,"gl",'scrollbars=yes,menubar=no,status=yes,resizeble=yes,width='+w+',height='+h);
}

function updateCart(f)
{
    var bsmit=f.butsubmit;
    bsmit.oldvl=bsmit.value;
    bsmit.value='Sending...';
    ajaxCart.init({url: f.action,func:upcartsuccess});
    ajaxCart.send(f,true);    
    return false;
}

function upcartsuccess(obj)
{
    if(obj.status=='ok')
    {
        getId('listcart').innerHTML=obj.msg;
        getId('listcartright').innerHTML=obj.cart;        
       // getId('countproduct').innerHTML=obj.count;
    }else
    {
        alert(obj.msg);
    }
}
function delrow(id)
{
   getId('cart_'+id).style.display='none';
   getId('count_'+id).value=-1;
}
function Talert(msg)
{    
    idobj=document.getElementById('alertmsg');
    idobj.className='AlertMsg';
    if(msg=='')
    {
        idobj.className='';
    }
    idobj.innerHTML=msg;
}
function show_page(a,divshow)
{
    ajaxPage.init({url:location.href,func:show_page_succ});
    ajaxPage.send('page='+a.innerHTML);
    ajaxPage.divshow    = divshow;
    getId(divshow+'_loading').innerHTML='Loading...';
}
function show_page_succ(obj)
{
    getId(ajaxPage.divshow).innerHTML=obj;
}
function search(f)
{
    location.href=url_root+'search/'+f.inputsearch.value;
    return false;
}